#include "DALUtils.h"

void AllocateMemories()
{
	DALCache = malloc(sizeof(void*) * EnvironmentEntityTable.Size);
	DALFileEnvironment = malloc(sizeof(void*) * EnvironmentEntityTable.Size);;
}

void FreeMemories()
{
	free(DALCache);
	free(DALFileEnvironment);

	DALCache = NULL;
	DALFileEnvironment = NULL;
}

//TODO: Implement
int CheckDirectoryPath(String DirectoryPath)
{
	return 1;
}

//TODO: Implement
int CheckEntityTable(EntityTable EntityTable)
{
	return 1;
}

int GetEntityTypeIndex(String EntityType)
{
	unsigned int i;
	for (i = 0; i < EnvironmentEntityTable.Size; i++)
	{
		if (_strcmpi(EnvironmentEntityTable.Entities[i], EntityType) == 0)
			return i;
	}

	return -1;
}

DataEntity CopyDataEntity(DataEntity* DE)
{
	DataEntity newDE;

	newDE.Bytes = DE->Bytes;

	if (DE->Data)
	{
		newDE.Data = malloc(newDE.Bytes);
		memcpy(newDE.Data, DE->Data, newDE.Bytes);
	}
	else
		newDE.Data = NULL;

	return newDE;
}

void DestructDataEntity(DataEntity* DE)
{
	if (DE->Data)
		free(DE->Data);

	DE->Data = NULL;
	DE->Bytes = 0;
}